package com.lxr0860.lxr0860production_test.utils;

import android.app.Activity;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;

public class RefreshViewUtils {

    /**
     * 更新TextView文本内容
     */
    public static void setText(final Activity activity, final TextView tv, final String str) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                tv.setText(str);
            }
        });
    }

    /**
     * 更新控件可用状态
     */
    public static void enableView(final Activity activity, final View view, final Boolean enabled) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                view.setEnabled(enabled);
            }
        });
    }

    /**
     * 更新控件可用状态
     */
    public static void visibleView(final Activity activity, final View view, final int visible) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                view.setVisibility(visible);
            }
        });
    }

    /**
     * 追加TextView文本内容
     */
    public static void appendText(final Activity activity, final TextView tv, final String str) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                tv.append(str);
            }
        });
    }

    /**
     * Scrollview滑动到最后
     */
    public static void scrollToEnd(final Activity activity, final ScrollView scrollView) {
        activity.runOnUiThread(new Runnable() {
            public void run() {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        });
    }

}
